import { http } from '../utils/request.js'

// 获取全部用户的等级信息
export const getAllUsersLevel = (config = {}) => {
  return http.get('/userlevel', {}, config)
}

// 获取指定用户的等级信息（用用户ID）
export const getUserLevel = (userId, config = {}) => {
  return http.get(`/userlevel/${userId}`, {}, config)
}

// 获取指定用户的称号列表
export const getUserTitles = (userId, config = {}) => {
  return http.get(`/userlevel/${userId}/titles`, {}, config)
}

// 获取所有可用称号
export const getAllTitles = (config = {}) => {
  return http.get('/userlevel/all-titles', {}, config)
}

// 获取等级排行榜
export const getLeaderboard = (config = {}) => {
  return http.get('/userlevel/leaderboard', {}, config)
}

// 更换称号
export const changeTitle = (data, config = {}) => {
  return http.post('/userlevel/change-title', {
    userId: data.userId,
    newTitle: data.newTitle
  }, config)
}

// 手动添加经验（测试/管理可选）
export const addExperience = (data, config = {}) => {
  return http.post('/userlevel/add-experience', {
    userId: data.userId,
    experience: data.experience
  }, config)
}

// 统一导出等级系统API
export const userLevelAPI = {
  getAllUsersLevel,
  getUserLevel,
  getUserTitles,
  getAllTitles,
  getLeaderboard,
  changeTitle,
  addExperience
} 